
import 'package:flutter/material.dart';
import 'package:flutter_trip/pages/home_page.dart';
import 'package:flutter_trip/pages/my_page.dart';
import 'package:flutter_trip/pages/search_page.dart';
import 'package:flutter_trip/pages/travel_page.dart';

class TabNavigator extends StatefulWidget {
  const TabNavigator({super.key});

  @override
  State<TabNavigator> createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  final PageController _controller = PageController(
    initialPage: 0,
  );
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue[50];
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
         controller: _controller,
        physics: NeverScrollableScrollPhysics(),
        children: [
          HomePage(),
          SearchPage(keyWord: '网红酒店',),
          TravelPage(),
          MyPage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index){
          _controller.jumpToPage(index);
          setState(() {
            _currentIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home,color: _defaultColor,),
            activeIcon: Icon(Icons.home,color: _activeColor,),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.search,color: _defaultColor,),
            activeIcon: Icon(Icons.search,color: _activeColor,),
            label: '搜索',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.card_travel,color: _defaultColor,),
            activeIcon: Icon(Icons.card_travel,color: _activeColor,),
            label: '旅拍',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.my_library_add,color: _defaultColor,),
            activeIcon: Icon(Icons.my_library_add,color: _activeColor,),
            label: '我的',
          )
        ],
      ),
    );
  }
}
